package com.hhxy.controller;

import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import com.github.xiaoymin.knife4j.annotations.ApiSupport;
import com.hhxy.annotation.ControllerLog;
import com.hhxy.handler.exception.CustomException;
import com.hhxy.model.dto.UserInfoDto;
import com.hhxy.model.dto.UserRegisterDto;
import com.hhxy.service.UserService;
import com.hhxy.utils.response.AppHttpCodeEnum;
import com.hhxy.utils.response.ResponseResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.Objects;

/**
 * @author ghp
 * @date 2023/4/29
 * @title
 * @description
 */
@Api(tags = {"前台接口", "用户管理"})
@ApiSupport(author = "ghp", order = 1)
@RestController
@RequestMapping("/user")
public class FeUserController {

    @Resource
    private UserService userService;

    @GetMapping("/userInfo")
    @ApiOperation(value = "查看个人信息")
    @ApiOperationSupport(author = "ghp", order = 1)
    @ControllerLog(businessName = "查看个人信息")
    public ResponseResult getUserInfo() {
        return userService.getUserInfo();
    }

    @PutMapping("/userInfo")
    @ApiOperation(value = "修改个人信息")
    @ApiOperationSupport(author = "ghp", order = 1)
    @ControllerLog(businessName = "修改个人信息")
    public ResponseResult updateUserInfo(@RequestBody UserInfoDto userInfoDto) {
        if (Objects.isNull(userInfoDto)) {
            throw new CustomException(AppHttpCodeEnum.CLIENT_USER_ERROR);
        }
        return userService.updateUserInfo(userInfoDto);
    }

    @PostMapping("/register")
    @ApiOperation(value = "前台用户注册")
    @ApiOperationSupport(author = "ghp", order = 1)
    @ControllerLog(businessName = "前台用户注册")
    public ResponseResult register(@RequestBody UserRegisterDto userRegisterDto) {
        return userService.register(userRegisterDto);
    }
}
